home *** CD-ROM | disk | FTP | other *** search
/ 3D Games - Real-time Rend…ng & Software Technology / 3D Games - Real-time Rendering & Software Technology.iso / flysdk / lib / flyEngine / flyDraw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-03  |  14.1 KB  |  602 lines

  1. #include "..\Fly3D.h"
  2.  
  3. void flyEngine::draw_static_faces_cartoon(int *fd,int nfd)
  4. {
  5.     int i;
  6.     face *f;
  7.     tc->use(cartoonpicbsp);
  8.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
  9.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
  10.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
  11.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
  12.     glColor3ub(255,255,255);
  13.     glBegin(GL_TRIANGLES);
  14.     for( i=0;i<nfd;i++ )
  15.     {
  16.         f=&faces[fd[i]];
  17.         glTexCoord2f(f->uv[0][0],0.0f);
  18.         glColor3fv((float *)&vertcolor[f->vert[0]-vert]);
  19.         glVertex3fv((float *)f->vert[0]);
  20.         glTexCoord2f(f->uv[1][0],0.0f);
  21.         glColor3fv((float *)&vertcolor[f->vert[1]-vert]);
  22.         glVertex3fv((float *)f->vert[1]);
  23.         glTexCoord2f(f->uv[2][0],0.0f);
  24.         glColor3fv((float *)&vertcolor[f->vert[2]-vert]);
  25.         glVertex3fv((float *)f->vert[2]);
  26.     }
  27.     glEnd();
  28. }
  29.  
  30. void flyEngine::draw_static_faces(int *fd,int nfd)
  31. {
  32.     int i,mapcount=0;
  33.     face *f;
  34.  
  35.     glColor3ub(255,255,255);
  36.     glDepthMask(GL_TRUE);
  37.     glDepthFunc(GL_LESS);
  38.     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  39.  
  40.     // if using multitexture
  41.     if (multitexture && ntextureunits>1 && nlm)
  42.     {
  43.         // use two texture units
  44.         glBegin(GL_TRIANGLES);
  45.         for( i=0;i<nfd;i++ )
  46.             {
  47.             f=&faces[fd[i]];
  48.             tc->use_triangles(f->texpic,0);
  49.             if (f->lm!=-1)
  50.                 tc->use_triangles(lm[f->lm]->pic+lmbase,1);
  51.             else tc->use_triangles(-1,1);
  52.             glMultiTexCoord2fvARB(GL_TEXTURE0_ARB,f->uv[0]);
  53.             glMultiTexCoord2fvARB(GL_TEXTURE1_ARB,f->lmuv[0]);
  54.             glVertex3fv((float *)f->vert[0]);
  55.             glMultiTexCoord2fvARB(GL_TEXTURE0_ARB,f->uv[1]);
  56.             glMultiTexCoord2fvARB(GL_TEXTURE1_ARB,f->lmuv[1]);
  57.             glVertex3fv((float *)f->vert[1]);
  58.             glMultiTexCoord2fvARB(GL_TEXTURE0_ARB,f->uv[2]);
  59.             glMultiTexCoord2fvARB(GL_TEXTURE1_ARB,f->lmuv[2]);
  60.             glVertex3fv((float *)f->vert[2]);
  61.             }
  62.         glEnd();
  63.         tc->use(-1,1);
  64.         tc->use(-1);
  65.         mapcount+=2;
  66.     }
  67.     else // not using multitexture
  68.     {
  69.         // texture layer
  70.         if (mapmode&MAPPING_TEXTURE)
  71.         {
  72.             glDisable(GL_TEXTURE_2D);
  73.             glBegin(GL_TRIANGLES);
  74.             if (vertcolor)    // use vertex colors?
  75.                 for( i=0;i<nfd;i++ )
  76.                     {
  77.                     f=&faces[fd[i]];
  78.                     tc->use_triangles(f->texpic);
  79.                     glTexCoord2fv(f->uv[0]);
  80.                     glColor3fv((float *)&vertcolor[f->vert[0]-vert]);
  81.                     glVertex3fv((float *)f->vert[0]);
  82.                     glTexCoord2fv(f->uv[1]);
  83.                     glColor3fv((float *)&vertcolor[f->vert[1]-vert]);
  84.                     glVertex3fv((float *)f->vert[1]);
  85.                     glTexCoord2fv(f->uv[2]);
  86.                     glColor3fv((float *)&vertcolor[f->vert[2]-vert]);
  87.                     glVertex3fv((float *)f->vert[2]);
  88.                     }
  89.             else
  90.                 for( i=0;i<nfd;i++ )
  91.                     {
  92.                     f=&faces[fd[i]];
  93.                     tc->use_triangles(f->texpic);
  94.                     glTexCoord2fv(f->uv[0]);
  95.                     glVertex3fv((float *)f->vert[0]);
  96.                     glTexCoord2fv(f->uv[1]);
  97.                     glVertex3fv((float *)f->vert[1]);
  98.                     glTexCoord2fv(f->uv[2]);
  99.                     glVertex3fv((float *)f->vert[2]);
  100.                     }
  101.             glEnd();
  102.             glColor3ub(255,255,255);
  103.             mapcount++;
  104.         }
  105.         
  106.         // detail layer
  107.         if (mapmode&MAPPING_DETAIL)
  108.         if (detailpic!=-1)
  109.             {
  110.             if (mapcount)
  111.                 {
  112.                 glBlendFunc(GL_ZERO,GL_SRC_COLOR);
  113.                 glDepthMask(GL_FALSE);
  114.                 glDepthFunc(GL_EQUAL);
  115.                 }
  116.             tc->use(detailpic);
  117. //            glMatrixMode( GL_TEXTURE );
  118. //            glScalef(detailtile,detailtile,1.0f);
  119.             glBegin(GL_TRIANGLES);
  120.             for( i=0;i<nfd;i++ )
  121.             {
  122.                 f=&faces[fd[i]];
  123.                 glTexCoord2f(f->uv[0][0]*detailtile,f->uv[0][1]*detailtile);
  124.                 glVertex3fv((float *)f->vert[0]);
  125.                 glTexCoord2f(f->uv[1][0]*detailtile,f->uv[1][1]*detailtile);
  126.                 glVertex3fv((float *)f->vert[1]);
  127.                 glTexCoord2f(f->uv[2][0]*detailtile,f->uv[2][1]*detailtile);
  128.                 glVertex3fv((float *)f->vert[2]);
  129.             }
  130.             glEnd();
  131. //            glLoadIdentity();
  132. //            glMatrixMode( GL_MODELVIEW );
  133.             mapcount++;
  134.             }
  135.  
  136.         // lightmap layer
  137.         if (mapmode&MAPPING_LIGHTMAP)
  138.         if (nlm!=NULL)
  139.             {
  140.             if (mapcount)
  141.                 {
  142.                 glBlendFunc(GL_ZERO,GL_SRC_COLOR);
  143.                 glDepthMask(GL_FALSE);
  144.                 glDepthFunc(GL_EQUAL);
  145.                 }
  146.             glBegin(GL_TRIANGLES);
  147.             for( i=0;i<nfd;i++ )
  148.                 {
  149.                 f=&faces[fd[i]];
  150.                 if (f->lm!=-1)
  151.                     {
  152.                     tc->use_triangles(lm[f->lm]->pic+lmbase);
  153.                     glTexCoord2fv(f->lmuv[0]);
  154.                     glVertex3fv((float *)f->vert[0]);
  155.                     glTexCoord2fv(f->lmuv[1]);
  156.                     glVertex3fv((float *)f->vert[1]);
  157.                     glTexCoord2fv(f->lmuv[2]);
  158.                     glVertex3fv((float *)f->vert[2]);
  159.                     }
  160.                 }
  161.             glEnd();
  162.             mapcount++;
  163.             }
  164.     }
  165.  
  166.     // fogmap layer
  167.     if (mapmode&MAPPING_FOGMAP)
  168.     if (nlm!=0)
  169.         {
  170.         if (mapcount)
  171.             {
  172.             glDepthMask(GL_FALSE);
  173.             glDepthFunc(GL_EQUAL);
  174.             glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  175.             }
  176.         glBegin(GL_TRIANGLES);
  177.         for( i=0;i<nfd;i++ )
  178.             {
  179.             f=&faces[fd[i]];
  180.             if (f->lm!=-1)
  181.             if (fm[f->lm]->lastupdate>=flyengine->cur_step_base)
  182.                 {
  183.                 tc->use_triangles(fm[f->lm]->pic+fmbase);
  184.                 glTexCoord2fv(f->lmuv[0]);
  185.                 glVertex3fv((float *)f->vert[0]);
  186.                 glTexCoord2fv(f->lmuv[1]);
  187.                 glVertex3fv((float *)f->vert[1]);
  188.                 glTexCoord2fv(f->lmuv[2]);
  189.                 glVertex3fv((float *)f->vert[2]);
  190.                 }
  191.             }
  192.         glEnd();
  193.         }
  194.  
  195.     tc->use(-1);
  196.     glDepthMask(GL_TRUE);
  197.     glDepthFunc(GL_LESS);
  198.     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  199. }
  200.  
  201. void mesh::draw()
  202. {
  203.     lastdraw=flyengine->cur_frame;
  204.     int i;
  205.     glBegin(GL_TRIANGLES);
  206.     for( i=0;i<nf;i++ )
  207.         {
  208.         tc->use_triangles(localfaces[i].texpic);
  209.  
  210.         glColor4f(
  211.             color.x*localfaces[i].color.x,
  212.             color.y*localfaces[i].color.y,
  213.             color.z*localfaces[i].color.z,
  214.             color.w*localfaces[i].color.w);
  215.     
  216.         glNormal3fv(&localfaces[i].vertnormal[0].x);
  217.         glTexCoord2f(localfaces[i].uv[0][0]+scrollu,localfaces[i].uv[0][1]+scrollv);
  218.         glVertex3fv(&localfaces[i].vert[0]->x);
  219.  
  220.         glNormal3fv(&localfaces[i].vertnormal[1].x);
  221.         glTexCoord2f(localfaces[i].uv[1][0]+scrollu,localfaces[i].uv[1][1]+scrollv);
  222.         glVertex3fv(&localfaces[i].vert[1]->x);
  223.  
  224.         glNormal3fv(&localfaces[i].vertnormal[2].x);
  225.         glTexCoord2f(localfaces[i].uv[2][0]+scrollu,localfaces[i].uv[2][1]+scrollv);
  226.         glVertex3fv(&localfaces[i].vert[2]->x);
  227.         }
  228.     glEnd();
  229. }
  230.  
  231. void flyEngine::start_text_mode()
  232. {
  233.     glMatrixMode(GL_PROJECTION);
  234.     glLoadIdentity();
  235.     glOrtho(0,screen_sx,0,screen_sy,-1,1);
  236.     glMatrixMode(GL_MODELVIEW);
  237.     glLoadIdentity();
  238.     glDisable(GL_DEPTH_TEST);
  239.     glDisable(GL_FOG);
  240.     glDepthMask(GL_FALSE);
  241.     glBlendFunc(GL_ONE,GL_ONE);
  242.     glColor3ub(255,255,255);
  243. }
  244.  
  245. int flyEngine::draw_text(int x,int y,char *text)
  246. {
  247.     int len=strlen(text),i,s=0;
  248.     float xx,yy,xy=1.0f/FONTS_NUM;
  249.  
  250.     y=screen_sy-y-FONTS_SIZE;
  251.     for( i=0;i<len;i++ )
  252.         s+=flyengine->fonts_width[text[i]-32];
  253.  
  254.     tc->use(fontspic);
  255.  
  256.     for( i=0;i<len;i++ )
  257.         {
  258.         xx=((text[i]-32)%FONTS_NUM)*xy;
  259.         yy=((text[i]-32)/FONTS_NUM)*xy;
  260.  
  261.         glColor3ub(255,255,255);
  262.         glBegin(GL_QUADS);
  263.         glTexCoord2f(xx+xy,yy+xy);
  264.         glVertex2i(x+FONTS_SIZE,y);
  265.  
  266.         glTexCoord2f(xx+xy,yy);
  267.         glVertex2i(x+FONTS_SIZE,y+FONTS_SIZE);
  268.  
  269.         glTexCoord2f(xx,yy);
  270.         glVertex2i(x,y+FONTS_SIZE);
  271.  
  272.         glTexCoord2f(xx,yy+xy);
  273.         glVertex2i(x,y);
  274.         glEnd();
  275.  
  276.         x+=flyengine->fonts_width[text[i]-32];
  277.         }
  278.     
  279.     return s;
  280. }
  281.  
  282. int flyEngine::draw_text_center(int x,int y,char *text)
  283. {
  284.     int len=strlen(text),i,s=0;
  285.     float xx,yy,xy=1.0f/FONTS_NUM;
  286.  
  287.     y=screen_sy-y-FONTS_SIZE;
  288.     for( i=0;i<len;i++ )
  289.         s+=flyengine->fonts_width[text[i]-32];
  290.     x-=s/2;
  291.  
  292.     tc->use(fontspic);
  293.  
  294.     for( i=0;i<len;i++ )
  295.         {
  296.         xx=((text[i]-32)%FONTS_NUM)*xy;
  297.         yy=((text[i]-32)/FONTS_NUM)*xy;
  298.         glColor3ub(255,255,255);
  299.         glBegin(GL_QUADS);
  300.         glTexCoord2f(xx+xy,yy+xy);
  301.         glVertex2i(x+FONTS_SIZE,y);
  302.  
  303.         glTexCoord2f(xx+xy,yy);
  304.         glVertex2i(x+FONTS_SIZE,y+FONTS_SIZE);
  305.  
  306.         glTexCoord2f(xx,yy);
  307.         glVertex2i(x,y+FONTS_SIZE);
  308.  
  309.         glTexCoord2f(xx,yy+xy);
  310.         glVertex2i(x,y);
  311.         glEnd();
  312.  
  313.         x+=flyengine->fonts_width[text[i]-32];
  314.         }
  315.     
  316.     return s;
  317. }
  318.  
  319. void flyEngine::end_text_mode()
  320. {
  321.     glBlendFunc(GL_ONE,GL_ONE);
  322.     glColor3ub(255,255,255);
  323.  
  324.     if (crosshairpic!=-1)
  325.         {
  326.         int i,j;
  327.         i=screen_sx>>1;
  328.         j=screen_sy>>1;
  329.         tc->use(crosshairpic);
  330.         glBegin(GL_QUADS);
  331.             glTexCoord2f(0,1);
  332.             glVertex2i(i-crosshairsize,j-crosshairsize);
  333.             glTexCoord2f(1,1);
  334.             glVertex2i(i+crosshairsize,j-crosshairsize);
  335.             glTexCoord2f(1,0);
  336.             glVertex2i(i+crosshairsize,j+crosshairsize);
  337.             glTexCoord2f(0,0);
  338.             glVertex2i(i-crosshairsize,j+crosshairsize);
  339.         glEnd();
  340.         }
  341.     
  342.     if (cur_time - status_msg_time < 2000)
  343.         draw_text( screen_sx/2, 0, status_msg );
  344.  
  345.     if (filter.x>0 || filter.y>0 || filter.z>0)
  346.         {
  347.         tc->use(-1);
  348.         glColor3fv(&filter.x);
  349.         glRecti(0, 0, screen_sx, screen_sy);
  350.         glColor3ub(255,255,255);
  351.         }
  352.     
  353.     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  354.     if (introtime>0 && intropic!=-1)
  355.     {
  356.         int i;
  357.         if (introtime>1000)
  358.             i=0;
  359.         else i=screen_sy-introtime*screen_sy/1000;
  360.         introtime-=flyengine->cur_dt;
  361.         tc->use(intropic);
  362.         glBegin(GL_QUADS);
  363.             glTexCoord2f(0,1);
  364.             glVertex2i(0,i);
  365.             glTexCoord2f(1,1);
  366.             glVertex2i(screen_sx,i);
  367.             glTexCoord2f(1,0);
  368.             glVertex2i(screen_sx,i+screen_sy);
  369.             glTexCoord2f(0,0);
  370.             glVertex2i(0,i+screen_sy);
  371.         glEnd();
  372.     }
  373.     
  374.     if (flyengine->con.mode)
  375.         flyengine->con.draw();
  376.  
  377.     glEnable(GL_DEPTH_TEST);
  378.     glDepthMask(GL_TRUE);
  379.     if (fog)
  380.         glEnable(GL_FOG);
  381.     tc->use(-1);
  382. }
  383.  
  384. void anim_mesh::draw()
  385. {
  386.     int i,j,k,n;
  387.     tc->use(texpic);
  388.     if (nstripfan)
  389.         {
  390.             glCullFace(GL_FRONT);
  391.             glColor3fv(&color.x);
  392.             k=0;
  393.             for( i=0;i<nstripfan;i++ )
  394.             {
  395.                 n=abs(stripfancount[i]);
  396.                 if (stripfancount[i]>0)
  397.                     glBegin(GL_TRIANGLE_STRIP);
  398.                 else glBegin(GL_TRIANGLE_FAN);
  399.  
  400.                 for( j=0;j<n;j++,k++ )
  401.                     {
  402.                     glTexCoord2fv(&vertdata[k].u);
  403.                     glNormal3fv(&vertnorm[stripfanvert[k]].x);
  404.                     glVertex3fv((float *)&vert[stripfanvert[k]]);
  405.                     }
  406.  
  407.                 glEnd();
  408.             }
  409.             glCullFace(GL_BACK);
  410.         }
  411.     else 
  412.         {
  413.             glColor3fv(&color.x);
  414.             glBegin(GL_TRIANGLES);
  415.             for( i=0;i<nf;i++ )
  416.             {
  417.                 glTexCoord2fv(localfaces[i].uv[0]);
  418.                 glNormal3fv(&localfaces[i].vertnormal[0].x);
  419.                 glVertex3fv((float *)localfaces[i].vert[0]);
  420.  
  421.                 glTexCoord2fv(localfaces[i].uv[1]);
  422.                 glNormal3fv(&localfaces[i].vertnormal[1].x);
  423.                 glVertex3fv((float *)localfaces[i].vert[1]);
  424.  
  425.                 glTexCoord2fv(localfaces[i].uv[2]);
  426.                 glNormal3fv(&localfaces[i].vertnormal[2].x);
  427.                 glVertex3fv((float *)localfaces[i].vert[2]);
  428.             }
  429.             glEnd();
  430.         }
  431. }
  432.  
  433. void bsp_object::draw()
  434. {
  435.     mesh *objmesh=get_mesh();
  436.     if (objmesh)
  437.     {
  438.         glPushMatrix();
  439.         glTranslatef(pos.x,pos.y,pos.z);
  440.         glMultMatrixf((float *)&mat);
  441.         objmesh->draw();
  442.         glPopMatrix();
  443.     }
  444. }
  445.  
  446. void mesh::draw_cartoon(vector& campos,vector& light,light_vertex& lights,float edgewidth)
  447. {
  448.     int i,j;
  449.     float dot;
  450.     vector dir;
  451.     static float vtc[MAX_VERT];
  452.  
  453.     // compute light factor for each mesh vertex
  454.     memset(vtc,0,sizeof(float)*nv);
  455.     for( j=0;j<lights.nlights;j++ )
  456.     {
  457.         // compute color change
  458.         dot=lights.pos[j].length()/lights.radius[j];
  459.         if (dot<1.0f)
  460.             light+=lights.color[j]*(1.0f-dot);
  461.  
  462.         // compute vertex intensity
  463.         for( i=0;i<nv;i++ )
  464.         {
  465.             dir=lights.pos[j]-vert[i];
  466.             dir.normalize();
  467.             dot=vec_dot(dir,vertnorm[i]);
  468.             if (FP_SIGN_BIT(dot)==0)
  469.                 vtc[i]+=dot;
  470.         }
  471.     }
  472.  
  473.     // draw using the 1D texture and vertex light factors
  474.     tc->use(flyengine->cartoonpic);
  475.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
  476.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
  477.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
  478.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
  479.     glBegin(GL_TRIANGLES);
  480.     for( i=0;i<nf;i++ )
  481.     {
  482.         glColor3f(
  483.             localfaces[i].color.x*light.x,
  484.             localfaces[i].color.y*light.y,
  485.             localfaces[i].color.z*light.z);
  486.  
  487.         glTexCoord2f(vtc[localfaces[i].vert[0]-vert],0);
  488.         glVertex3fv((float *)localfaces[i].vert[0]);
  489.  
  490.         glTexCoord2f(vtc[localfaces[i].vert[1]-vert],0);
  491.         glVertex3fv((float *)localfaces[i].vert[1]);
  492.  
  493.         glTexCoord2f(vtc[localfaces[i].vert[2]-vert],0);
  494.         glVertex3fv((float *)localfaces[i].vert[2]);
  495.     }
  496.     glEnd();
  497.  
  498.     // draw outline as lines without texture
  499.     tc->use(-1);
  500.     glDepthMask(GL_FALSE);
  501.     glLineWidth(edgewidth);
  502.     glColor3fv(&flyengine->cartooncolor.x);
  503.  
  504.     glBegin(GL_LINES);
  505.     // for each edge
  506.     for( i=j=0;i<nedges;i++,j+=4 )
  507.     {
  508.         // check is edge is shared by a frontface and a backface
  509.         dir=campos-vert[edges[j]];
  510.         if (edges[j+3]==-1 || 
  511.             vec_dot(dir,localfaces[edges[j+2]].normal)*
  512.             vec_dot(dir,localfaces[edges[j+3]].normal)<0.0f)
  513.         {
  514.             // if so, draw edge
  515.             glVertex3fv((float *)&vert[edges[j]]);
  516.             glVertex3fv((float *)&vert[edges[j+1]]);
  517.         }
  518.     }
  519.     glEnd();
  520.  
  521.     glLineWidth(1.0f);
  522.     glColor3ub(255,255,255);
  523.     glDepthMask(GL_TRUE);
  524. }
  525.  
  526. void flyEngine::draw_bsp_edges()
  527. {
  528.     int i,j,e;
  529.     vector dir;
  530.     
  531.     tc->use(-1);
  532.     glDepthMask(GL_FALSE);
  533.     glLineWidth(cartoonwidth);
  534.     glColor3fv(&cartooncolor.x);
  535.  
  536.     glBegin(GL_LINES);
  537.     for( j=0;j<3;j++ )
  538.         for( i=0;i<nfacedraw;i++ )
  539.         {
  540.         e=faceedges[facedraw[i]*3+j]*5;
  541.         if (edges[e+4]<cur_frame)
  542.             {
  543.             edges[e+4]=cur_frame;
  544.             dir=flyengine->cam->pos-vert[edges[e]];
  545.             if (edges[e+3]==-1 || 
  546.                 vec_dot(dir,faces[edges[e+2]].normal)*
  547.                 vec_dot(dir,faces[edges[e+3]].normal)<0.0f)
  548.                 {
  549.                 glVertex3fv(&vert[edges[e]].x);
  550.                 glVertex3fv(&vert[edges[e+1]].x);
  551.                 }
  552.             }
  553.         }
  554.     glEnd();
  555.  
  556.     glLineWidth(1.0f);
  557.     glColor3ub(255,255,255);
  558.     glDepthMask(GL_TRUE);
  559. }
  560.  
  561. void mesh::draw_shadow_volume(vector& lightdir)
  562. {
  563.     static vector v[8];
  564.  
  565.     tc->use(-1);
  566.     glEnableClientState(GL_VERTEX_ARRAY);
  567.     glEnable(GL_STENCIL_TEST);
  568.     glStencilFunc(GL_ALWAYS,0,~0);
  569.     glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
  570.     glDepthMask(GL_FALSE);
  571.  
  572.     for( int i=0;i<nf;i++ )
  573.     if (vec_dot(localfaces[i].normal,lightdir)>0)
  574.         {
  575.         v[0]=*localfaces[i].vert[0];
  576.         v[1]=v[0]-lightdir;
  577.         v[2]=*localfaces[i].vert[1];
  578.         v[3]=v[2]-lightdir;
  579.         v[4]=*localfaces[i].vert[2];
  580.         v[5]=v[4]-lightdir;
  581.         v[6]=v[0];
  582.         v[7]=v[1];
  583.  
  584.         glVertexPointer(3,GL_FLOAT,sizeof(vector),v);
  585.  
  586.         glStencilOp(GL_KEEP,GL_KEEP,GL_INCR);
  587.         glCullFace(GL_BACK);
  588.         glDrawArrays(GL_QUAD_STRIP,0,8);
  589.  
  590.         glStencilOp(GL_KEEP,GL_KEEP,GL_DECR);
  591.         glCullFace(GL_FRONT);
  592.         glDrawArrays(GL_QUAD_STRIP,0,8);
  593.         }
  594.  
  595.     glDisableClientState(GL_VERTEX_ARRAY);
  596.     glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
  597.     glDisable(GL_STENCIL_TEST);
  598.     glCullFace(GL_BACK);
  599.     glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
  600.     glDepthMask(GL_TRUE);
  601. }
  602.